<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100%;
        }

        a{
            text-decoration: none;
        }

        ul {
            list-style: none;
        }

        li {
            float: left;
            margin: 10px;
        }

        li a img {
            width: 200px;
            height: 170px;

        }

        #img{
            width: 300px;
            height: 400px;
        }
    </style>
</head>

<body>

    <div class="box">
        <ul class="imgs">
            <li><a href="../imgs/1.jpg" title="图1"><img src="../imgs/1.jpg" alt=""></a></li>
            <li><a href="../imgs/2.jpg" title="图2"><img src="../imgs/2.jpg" alt=""></a></li>
            <li><a href="../imgs/3.jpg" title="图3"><img src="../imgs/3.jpg" alt=""></a></li>
        </ul>
    </div>
    <p id="des">选择一张图片</p>
    <img src="" id="img">
    <script>
        let ul = document.querySelector('.imgs')
        let aArrs = ul.getElementsByTagName('a')  //获取标签a
        let banner = document.querySelector('.banner')
        let img = document.getElementById('img')
        let des = document.getElementById('des')

        //循环绑定事件
        for (let i = 0; i < aArrs.length; i++) {
            aArrs[i].onclick = function () {
                //改变属性
                img.src = this.href
                des.innerHTML = this.title

                //停止执行后续代码
                return false
            }
        }
    </script>
</body>

</html>